home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / uw_1.exe / UW_TUT9.C < prev    next >
Text File  |  1992-11-02  |  21KB  |  565 lines

  1. /****************************************************************************/
  2. /* UW_TUT9.C                                                                */
  3. /*                                                                          */
  4. /* NOTE: THIS FILE IS PUBLIC DOMAIN AND MAY BE MODIFIED AND USED AT WILL    */
  5. /*                                                                          */
  6. /* In this tutorial we show how easy it is to run in graphics mode, instead */
  7. /* of the 80x25 text mode we have been using.                               */
  8. /*                                                                          */
  9. /*                                                         Dr. Boyd Gafford */
  10. /*                                                         Kevin Huck       */
  11. /*                                                         EnQue Software   */
  12. /*                                                         09/16/92         */
  13. /****************************************************************************/
  14. #include <stdio.h>
  15. #include <fcntl.h>
  16. #include <io.h>
  17. #ifndef __TURBOC__
  18. #include <sys\types.h>
  19. #endif
  20. #include <sys\stat.h>
  21. #include <time.h>
  22. #include <ctype.h>
  23. #include <bios.h>
  24. #ifdef __ZTC__
  25.   #include <fg.h>                         /* include Zortech graphics       */
  26. #else
  27. #ifdef M_I86
  28.   #include <graph.h>                      /* include Microsoft graphics     */
  29. #endif
  30. #endif
  31. #ifdef __TURBOC__
  32.   #include <graphics.h>                   /* include Borland graphics       */
  33. #endif
  34. #include "uw.h"                           /* include the necessary headers  */
  35.  
  36.  
  37. #define MAX_CUST 50
  38.  
  39. typedef struct cust
  40. {
  41.   int status;
  42.   int cust_no;
  43.   char business[34];
  44.   char name[34];
  45.   char addr[34];
  46.   char city[34];
  47.   char state[4];
  48.   char zip[10];
  49.   char phone[16];
  50.   char fax[16];
  51.   char date[10];
  52.   char memo[34];
  53.   char unused[26];                                /* round out to 256 bytes */
  54. } CUST;
  55.  
  56. /*------------------------ global window variables -------------------------*/
  57. WINDOW  Desk_wn, Window1;
  58. CUST    Customers[MAX_CUST];
  59. char    Fname[33];
  60.  
  61. MENU    Top_menu, *Top_mnp = &Top_menu;
  62. MENU    Files_menu, Edit_menu, Print_menu;
  63. MENU    *Drop_mnps[3];
  64.  
  65. PRINT   Print;
  66.  
  67. /*-------------------------------- prototypes ------------------------------*/
  68. void init_g(void);
  69. void end_g(void);
  70. int disp_time(void);
  71. void disp_cust(CUST *cp, WINDOW *wnp);
  72. int file_load(CUST *customers);
  73. int file_save(CUST *customers);
  74. int get_fname(char *fname);
  75. void print_cust(CUST *cp, PRINT *p);
  76.  
  77. /*********/
  78. /* ~main */
  79. /*       ********************************************************************/
  80. /*  Demonstrate data entry capability...                                    */
  81. /****************************************************************************/
  82. int main()
  83. {
  84.   int i, ret_val, cust = 0, end_flag = 0, print_stat = 0;
  85.   WINDOW *wnp;
  86.   CUST *cp;
  87.   uchar back_att  = (LIGHTGRAY << 4) | BLACK,
  88.         bdr_att   = (LIGHTGRAY << 4) | BLACK,
  89.         csr_att   = (CYAN << 4) | YELLOW,
  90.         first_att = (LIGHTGRAY << 4) | RED;
  91.   
  92.   wnp = &Window1;                         /* set local window pointer       */
  93. #ifdef __ZTC__
  94.   force_video(16, 80, 25);                /* force Zortech to EGA mode      */
  95. #else
  96.   init_video(80, 25);                     /* init video for 80 x 25 screen  */
  97. #endif
  98.   init_clock(0x3333);                     /* init clock irq at 91 tics/sec  */
  99.   init_mouse();                           /* init mouse if available        */
  100.   
  101.   init_uw_graphics(640, 350, 14, 14, -1, -1);
  102.   init_g();
  103.   
  104.   wn_create(0, 0, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, &Desk_wn);
  105.   link_window(&Desk_wn);
  106.  
  107.   /*------------------------ create the menu system ------------------------*/
  108.   Drop_mnps[0] = &Files_menu;
  109.   Drop_mnps[1] = &Edit_menu;
  110.   Drop_mnps[2] = &Print_menu;
  111.  
  112.   menu_create(0, 0, V_cols - 1, 0, M_HORIZONTAL,
  113.               back_att, bdr_att, csr_att, first_att,
  114.               NO_BDR, WN_NORMAL, Top_mnp);
  115.   item_add( "   Files   ", 1, 3, &Top_menu );
  116.   item_add( "   Edit    ", 2, 3, &Top_menu );
  117.   item_add( "   Print   ", 8, 3, &Top_menu );
  118.  
  119.   menu_create(0, 1, 14, 5, M_VERTICAL,
  120.     back_att, bdr_att, csr_att, first_att,
  121.     SGL_BDR, WN_NORMAL, Drop_mnps[0]);
  122.   item_add( " Load File", 4, 1, &Files_menu );
  123.   item_add( " Save File", 5, 1, &Files_menu );
  124.   item_add( "   Quit   ", 3, 3, &Files_menu );
  125.  
  126.   menu_create(11, 1, 32, 4, M_VERTICAL,
  127.     back_att, bdr_att, csr_att, first_att,
  128.     SGL_BDR, WN_NORMAL, Drop_mnps[1]);
  129.   item_add( " Clear Current", 6, 7, &Edit_menu );
  130.   item_add( " Clear All    ", 7, 7, &Edit_menu );
  131.  
  132.   menu_create(22, 1, 43, 4, M_VERTICAL,
  133.     back_att, bdr_att, csr_att, first_att,
  134.     SGL_BDR, WN_NORMAL, Drop_mnps[2]);
  135.   item_add( " Print Current", 9, 7, &Print_menu );
  136.   item_add( " Print All    ", 10, 7, &Print_menu );
  137.  
  138.   set_idle_func(disp_time);               /* set background clock function  */
  139.  
  140.   wn_create(5, 5, 75, 20, SLD_BDR, WN_POPUP, wnp);
  141.   wn_color(YELLOW, BLUE, wnp);            /* change the window colors       */
  142.   wn_bdr_color(WHITE, BLUE, wnp);         /* change the border's colors     */
  143.   link_window(wnp);
  144.  
  145.   /*------------- initialize first customer as EnQue Software --------------*/
  146.   cp = &Customers[0];
  147.   strcpy(cp->business, "EnQue Software"); 
  148.   strcpy(cp->name, "Kevin Huck & Boyd Gafford");  
  149.   strcpy(cp->addr, "Rt. 1 Box 116C"); 
  150.   strcpy(cp->city, "Pleasant Hill");  
  151.   strcpy(cp->state, "MO");  
  152.   strcpy(cp->zip, "64080"); 
  153.   strcpy(cp->phone, "(816)987-2515"); 
  154.   strcpy(cp->fax, "(816)987-2515");      
  155.   strcpy(cp->date, "09/11/92");      
  156.   strcpy(cp->memo, "BBS 816-358-8990"); 
  157.  
  158.   /*------------------------ initialize the printer ------------------------*/
  159.   if( init_printer("LPT1", NULL, 2048L, 2048L, &Print) )
  160.     print_stat = 1;
  161.  
  162.   Top_mnp->csr_pos = M_MAX_ENTRIES;    /* set to prevent menu from hiliting */
  163.   menu_set(Top_mnp);          /* on entry, since menu is not active until   */
  164.   Top_mnp->csr_pos = 0;       /* Alt-F, Alt-E, or Alt-P is hit              */
  165.  
  166.   wn_color(LIGHTGRAY, RED, &Desk_wn);
  167.   wn_plst(CENTERED, 3, "Use cursor keypad to select customer", &Desk_wn);
  168.   wn_plst(CENTERED, 4, "or click on cursor buttons at bottom of screen", &Desk_wn);
  169.   wn_plst(CENTERED, 22, "<Up> <Dn>  <PgUp> <PgDn>  <Home> <End>", &Desk_wn);
  170.   wn_color(YELLOW, RED, &Desk_wn);
  171.   while(!end_flag)
  172.   {
  173.     cp = &Customers[cust];
  174.     mv_cs(1,1, wnp);
  175.     wn_printf(wnp, "Customer:%3d", cust+1);
  176.     disp_cust(cp, wnp);
  177.     m_show();
  178.     wait_event();
  179.     m_hide();
  180.     if( Event.is_mouse )                            /* process mouse action */
  181.     {
  182.       if( range(0,Event.m_x,11) && (Event.m_y == 0) )
  183.         Event.key = KEY_ALT_F;
  184.       else if( range(11,Event.m_x,22) && (Event.m_y == 0) )
  185.         Event.key = KEY_ALT_E;
  186.       else if( range(22,Event.m_x,33) && (Event.m_y == 0) )
  187.         Event.key = KEY_ALT_P;
  188.  
  189.       else if( range( 7,Event.m_x,47) && (Event.m_y == 9) )
  190.         Event.key = 'B';
  191.       else if( range( 7,Event.m_x,47) && (Event.m_y == 10) )
  192.         Event.key = 'N';
  193.       else if( range( 7,Event.m_x,47) && (Event.m_y == 11) )
  194.         Event.key = 'A';
  195.       else if( range( 7,Event.m_x,47) && (Event.m_y == 12) )
  196.         Event.key = 'C';
  197.       else if( range(50,Event.m_x,59) && (Event.m_y == 12) )
  198.         Event.key = 'S';
  199.       else if( range(61,Event.m_x,71) && (Event.m_y == 12) )
  200.         Event.key = 'Z';
  201.       else if( range( 7,Event.m_x,47) && (Event.m_y == 13) )
  202.         Event.key = 'P';
  203.       else if( range( 7,Event.m_x,47) && (Event.m_y == 14) )
  204.         Event.key = 'F';
  205.       else if( range( 7,Event.m_x,47) && (Event.m_y == 15) )
  206.         Event.key = 'D';
  207.       else if( range( 7,Event.m_x,47) && (Event.m_y == 16) )
  208.         Event.key = 'M';
  209.  
  210.       else if( range( 21,Event.m_x,24) && (Event.m_y == 22) )
  211.         Event.key = KEY_UP;
  212.       else if( range( 26,Event.m_x,29) && (Event.m_y == 22) )
  213.         Event.key = KEY_DN;
  214.       else if( range( 32,Event.m_x,37) && (Event.m_y == 22) )
  215.         Event.key = KEY_PGUP;
  216.